package com.clement.observe;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Clement on 2017/2/28.
 */
@Getter
public class Subject {
    private List<Observer> observers = new ArrayList<>();
    private int state;
    public void setState (int state) {
        this.state = state;
        notifyAllObservers();
    }
    public void attach(Observer observer) {
        observers.add(observer);
    }
    public  void notifyAllObservers() {
        observers.forEach(Observer::update);
    }
}
